package com.lxl.hadoop.selfinputformat;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.BytesWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.InputSplit;
import org.apache.hadoop.mapreduce.JobContext;
import org.apache.hadoop.mapreduce.RecordReader;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;

import java.io.IOException;

/**
 * @Author lixilin
 * @Date 2021/12/25 10:45
 * @Description 自定义 inputFormat
 */
public class MyInputFormat extends FileInputFormat<Text, BytesWritable> {
    public RecordReader<Text, BytesWritable> createRecordReader(InputSplit split, TaskAttemptContext context) throws IOException, InterruptedException {
        RecordReader<Text, BytesWritable> recordReader = new MyRecordReader();
        recordReader.initialize(split,context);
        return recordReader;
    }
    // 不需要切片
    protected boolean isSplitable(JobContext context, Path filename) {
        return false;
    }
}
